<template>
  <div class="divBox">
    <el-card class="box-card">
      <el-form inline size="small" @submit.native.prevent>
        <el-form-item label="是否领取">
          <el-select v-model="listPram.isSend" placeholder="请选择" style="width: 200px;">
            <el-option
                v-for="item in isReceiveList"
                :key="item.id"
                :label="item.data"
                :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="商品类型">
          <el-select v-model="listPram.type" placeholder="请选择" style="width: 200px;">
            <el-option
                v-for="item in typeList"
                :key="item.id"
                :label="item.data"
                :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" size="mini" type="primary" @click.native="getList">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="listData.list" size="mini"
                :header-cell-style=" {fontWeight:'bold',background:'#f8f8f9',color: '#515a6e',height:'40px'}" border>
        <el-table-column label="ID" prop="id" coverImg="120"></el-table-column>
        <el-table-column label="中奖人昵称" min-width="130" prop="user.phone"/>
        <el-table-column label="中奖人手机号" min-width="130" prop="user.name"/>
        <el-table-column label="中奖奖品" prop="hitPrize" min-width="130"/>
        <el-table-column label="奖品类型" prop="type" min-width="130">
          <template slot-scope="scope">
            <div v-if="scope.row.type===1">实物</div>
            <div v-if="scope.row.type===2">益积分</div>
            <div v-if="scope.row.type===3">益联券</div>
          </template>
        </el-table-column>
        <el-table-column label="中奖时间" min-width="130" prop="drawTime"/>
        <el-table-column label="是否领取" prop="isSend" min-width="150">
          <template slot-scope="scope">
            <div v-if="scope.row.isSend===1" style="color: #e03e2d">未领取</div>
            <div v-else-if="scope.row.isSend===3" style="color: #022cff">待收货</div>
            <div v-else-if="scope.row.isSend===2" style="color: #00BFA1">已领取</div>
            <div v-else-if="scope.row.isSend===4" style="color: red">已失效</div>
          </template>
        </el-table-column>
<!--        <el-table-column label="操作" min-width="180" fixed="right" align="center">-->
<!--          <template slot-scope="scope">-->
<!--            <el-button icon="el-icon-edit" v-if="scope.row.isSend===1" size="mini" type="primary"-->
<!--                       @click="openSend(scope.row.id)" v-has-permi="['admin:commodity:save']">发送货-->
<!--            </el-button>-->
<!--            <el-button icon="el-icon-tickets" v-if="scope.row.type===1" size="mini" type="success"-->
<!--                       @click="openRecordInformation(scope.row.id)" v-has-permi="['admin:operate:shopping:record:detail']">详情-->
<!--            </el-button>-->
<!--&lt;!&ndash;            <el-button icon="el-icon-delete" size="mini" type="danger" @click="handlerDelete(scope.row.id)"&ndash;&gt;-->
<!--&lt;!&ndash;                       v-has-permi="['admin:commodity:delete']">删除&ndash;&gt;-->
<!--&lt;!&ndash;            </el-button>&ndash;&gt;-->
<!--          </template>-->
<!--        </el-table-column>-->
      </el-table>
      <el-pagination
          :current-page="listPram.page"
          :page-sizes="[20,40,60,80,100]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="listData.count"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
      />
    </el-card>
    <el-dialog
        :visible.sync="sendDialog.show"
        :title="'发货'"
        destroy-on-close
        :close-on-click-modal="false"
        width="1200px"
        top="80px">
      <send
          v-if="sendDialog.show"
          :id="sendDialog.id"
          @hideEditDialog="hideEditDialog"
          ref="editForm"
      />
    </el-dialog>
    <el-dialog
        :visible.sync="openRecordInformationDialog.show"
        :title="'详情'"
        destroy-on-close
        :close-on-click-modal="false"
        width="1200px"
        top="80px">
      <recordFormation
          v-if="openRecordInformationDialog.show"
          :id="openRecordInformationDialog.id"
          @hideEditDialog="hideEditDialog"
          ref="editForm"
      />
    </el-dialog>
  </div>
</template>


<script>


import {winningRecord} from "@/api/order";
import Send from "@/views/operate/shopping/draw/record/send.vue";
import RecordFormation from "@/views/operate/shopping/draw/record/recordFormation.vue";


export default {
  components: {RecordFormation, Send},
  data() {
    return {
      listData: {list: [], count: 0},
      listPram: {
        page: 1,
        limit: 20,
        isSend:'',
        type:''
      },
      editDialog: {
        show: false,
        id: null
      },
      sendDialog: {
        show: false,
        id: null
      },
      openRecordInformationDialog: {
        show: false,
        id: null
      },
      tableLoading: false,
      isReceiveList: [{id: 2, data: '已领取'}, {id: 1, data: '未领取'}, {id: 3, data: '待收货'}],
      typeList: [{id: 1, data: '实物'}, {id: 2, data: '益积分'}, {id: 3, data: '益联券'}]
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    openSend(id=null) {
      this.sendDialog.id = id;
      this.sendDialog.show = true
    },
    getList() {
      this.tableLoading = true
      winningRecord(this.listPram).then(res => {
        this.listData = res;
      }).finally(() => {
      })
      this.tableLoading = false;
    },
    openRecordInformation(id = null) {
      this.openRecordInformationDialog.id = id;
      this.openRecordInformationDialog.show = true
    },
    hideEditDialog() {
      this.sendDialog.show = false
      this.openRecordInformationDialog.show = false
      this.getList()
    },
    handleSizeChange(val) {
      this.listPram.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listPram.page = val
      this.getList()
    },
    resetQuery() {
      this.listPram.isSend = '';
      this.listPram.type = '';
      this.getList()
    }
  }
}
</script>

<style lang="sass" scoped>

</style>
